
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package be.ac.ua.pats.thesisrobotica.robot.main;

//~--- non-JDK imports --------------------------------------------------------

import lejos.nxt.ColorLightSensor;
import lejos.nxt.SensorPort;
import lejos.nxt.SensorPortListener;
import lejos.nxt.comm.RConsole;

/**
 *
 * @author Admin
 */
public class DetectionTest {
    static ColorLightSensor cSensor = new ColorLightSensor(SensorPort.S1, ColorLightSensor.TYPE_COLORFULL);

    enum lcd_line {
        LCD_LINE1, LCD_LINE2, LCD_LINE3, LCD_LINE4, LCD_LINE5, LCD_LINE6, LCD_LINE7, LCD_LINE8,
    }

    /**
     * void identify_ports() throws InterruptedException {
     *
     * int count,i;
     * String id,oldId;
     *
     * SensorPort.S1.setMode(SensorPort.TYPE_LOWSPEED);
     * SensorPort.S2.setMode(SensorPort.TYPE_LOWSPEED);
     * SensorPort.S3.setMode(SensorPort.TYPE_LOWSPEED);
     * SensorPort.S4.setMode(SensorPort.TYPE_LOWSPEED);
     *
     * Thread.sleep(50);
     *
     * count = 0;
     *
     * String port[] = new String[4];
     *
     * while(count != 4) {
     * while(count!=4) {
     * count=0;
     * for(i=0;i<4;i++) {
     * LowSpeedCheckStatus(5);
     * if(SensorPort.S1.!=0) {
     * SensorUS(i);
     * Wait(50);
     * }
     * if(LowspeedCheckStatus(i)!=0) {
     * id="Unknown";
     * SetSensorType(i, SENSOR_TYPE_NONE);
     * }
     * else
     * id= I2CDeviceId(i);
     *
     * old_id= port[i];
     * if(old_id == id) count++;
     * port[i]=id;
     * }
     * }
     * }
     * }
     *
     * }
     */
    public static void main(String[] args) throws InterruptedException {
        RConsole.openUSB(20000);
        RConsole.println("Start");
        SensorPort.S1.setTypeAndMode(SensorPort.TYPE_SWITCH, SensorPort.MODE_BOOLEAN);
        SensorPort.S1.addSensorPortListener(new SensorPortListener() {
            public void stateChanged(SensorPort sp, int i, int i1) {
                if (i1 < 600) {
                    RConsole.println("Pressed");
                }
            }
        });
        SensorPort.S2.addSensorPortListener(new SensorPortListener() {
            public void stateChanged(SensorPort sp, int i, int i1) {
                if (i1 < 1000) {
                    RConsole.println("T2 On");
                }
            }
        });

        SensorPort.S3.setTypeAndMode(SensorPort.TYPE_REFLECTION, SensorPort.MODE_RAW);
        SensorPort.S3.addSensorPortListener(new SensorPortListener() {
            public void stateChanged(SensorPort sp, int i, int i1) {
                RConsole.println("SensorPort S3: "+i1);
            }
        });
        SensorPort.S1.addSensorPortListener(new SensorPortListener() {
            public void stateChanged(SensorPort sp, int i, int i1) {
                int[] color = cSensor.getColor();

                RConsole.println(String.valueOf(cSensor.getColor()[0]) + " " + String.valueOf(cSensor.getColor()[1])
                                 + String.valueOf(cSensor.getColor()[1]));
            }
        });

        int    count;
        String id, oldId;

        SensorPort.S1.setMode(SensorPort.TYPE_LOWSPEED);
        SensorPort.S2.setMode(SensorPort.TYPE_LOWSPEED);
        SensorPort.S3.setMode(SensorPort.TYPE_LOWSPEED);
        SensorPort.S4.setMode(SensorPort.TYPE_LOWSPEED);
        Thread.sleep(50);

        count = 0;

        Thread.currentThread().join();
        RConsole.println("End");
        RConsole.close();
        System.exit(1);
    }
}
